 #include "LPC11xx.H"
 #define LED1_ON()  LPC_GPIO2->DATA&=~(1<<0)
 #define LED1_OFF() LPC_GPIO2->DATA|=(1<<0)
 #define LED2_ON()  LPC_GPIO2->DATA&=~(1<<1)
 #define LED2_OFF() LPC_GPIO2->DATA|=(1<<1)
 #define LED3_ON()  LPC_GPIO2->DATA&=~(1<<2)
 #define LED3_OFF() LPC_GPIO2->DATA|=(1<<2)
 void LedInit()
 {
	 LPC_SYSCON->SYSAHBCLKCTRL|=(1<<16);
	 LPC_IOCON->PIO2_0&=~0X07;
	 LPC_IOCON->PIO2_0|=0X00;
	 LPC_IOCON->PIO2_1&=~0X0b;
	 LPC_IOCON->PIO2_1|=0X00;
	 LPC_IOCON->PIO2_2&=~0X0d;
	 LPC_IOCON->PIO2_2|=0X00;
	 LPC_SYSCON->SYSAHBCLKCTRL=~(1<<16);
	 LPC_SYSCON->SYSAHBCLKCTRL|=(1<<6);
	 LPC_GPIO2->DIR|=(1<<0);
	 LPC_GPIO2->DATA|=(1<<0);
	 LPC_GPIO2->DIR|=(1<<1);
	 LPC_GPIO2->DATA|=(1<<1);
	 LPC_GPIO2->DIR|=(1<<2);
	 LPC_GPIO2->DATA|=(1<<2);
 }
 
 void T32B1_Init(void)
 {
	 LPC_SYSCON->SYSAHBCLKCTRL|=(1<<10);
	 LPC_TMR32B1->IR = 0X01;
	 LPC_TMR32B1->MCR = 0X04;
 }
 
 void T32B1_DelayMs(uint16_t ms)
 {
	 LPC_TMR32B1->TCR=0X02;
	 LPC_TMR32B1->PR=0;
	 LPC_TMR32B1->MR0 = ms * (SystemCoreClock/1000);
	 LPC_TMR32B1->TCR = 0X01;
	 while(LPC_TMR32B1->TCR&0X01);
 }
 
 int main()
 {
	 LedInit();
	 T32B1_Init();
	 while(1)
	 { int i;
		 for(i=0;i<3;i++)
		 {
		 T32B1_DelayMs(500);
		 LED1_ON();
		 T32B1_DelayMs(520);
		 LED2_ON();
		 T32B1_DelayMs(540);
		 LED3_ON();
		 T32B1_DelayMs(500);
		 LED1_OFF();
		 T32B1_DelayMs(520);
		 LED2_OFF();
		 T32B1_DelayMs(540);
		 LED3_OFF();
		 }
		 for(i=0;i<3;i++)
		 {
		 T32B1_DelayMs(560);
		 LED3_ON();
		 T32B1_DelayMs(580);
		 LED2_ON();
		 T32B1_DelayMs(600);
		 LED1_ON();
		 T32B1_DelayMs(560);
		 LED3_OFF();
		 T32B1_DelayMs(580);
		 LED2_OFF();
		 T32B1_DelayMs(600);
		 LED1_OFF();
		 }
		 for(i=0;i<3;i++)
		 {T32B1_DelayMs(620);
		 LED1_ON();LED2_ON();LED3_ON();
		 T32B1_DelayMs(640);
		 LED1_OFF();LED2_OFF();LED3_OFF();}
	 }
 }
 